//
//  JCPlanTableViewCell.m
//  JiFengDaRen
//
//  Created by 陈如意 on 2018/5/10.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "JCPlanTableViewCell.h"


@interface JCPlanTableViewCell()

@property (nonatomic, strong) UILabel * titleName;

@property (nonatomic, strong) UIImageView * iconImage;

@property (nonatomic, strong) UIView * line;


@end

@implementation JCPlanTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI{
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.titleName = [UILabel new];
    self.titleName.textColor = [UIColor colorWithHexString:@"#2C2C2C"];
    self.titleName.font = KSystemFont(__I6Width(14));
    [self addSubview:self.titleName];
    
    self.iconImage = [UIImageView new];
    self.iconImage.image = [UIImage imageNamed:@"jmarrow"];
    [self addSubview:self.iconImage];
    
    self.contentLabel = [UILabel new];
    self.contentLabel.textColor = [UIColor colorWithHexString:@"666666"];
    self.contentLabel.font = KSystemFont(__I6Width(14));
    self.contentLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.contentLabel];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.titleName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(__I6Width(15));
        make.centerY.equalTo(self);
        make.width.mas_offset(__I6Width(120));
    }];
    
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-__I6Width(15));
        make.centerY.equalTo(self);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self.iconImage.mas_left).offset(-__I6Width(10)).priority(500);
        make.right.equalTo(self).offset(-__I6Width(15)).priority(100);
    }];
}

+ (instancetype)tableViewCellWithTableView:(UITableView *)tableView{
    
    static NSString * cellIndentfile = @"JCPlanTableViewCell";
    JCPlanTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndentfile];
    
    if (!cell) {
        cell = [[JCPlanTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentfile];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)getPlanRepayment:(NSMutableDictionary *)dic andSection:(NSInteger)section andIndexRow:(NSInteger)row{
    self.titleName.text = dic[@"titleName"][section][row];
    self.contentLabel.text = dic[@"contentName"][section][row];
}


@end


@interface JCPlanFieldCell()

@property (nonatomic, strong) UILabel * titleName;

@property (nonatomic, strong) UIView * line;

@end

@implementation JCPlanFieldCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI{
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.titleName = [UILabel new];
    self.titleName.textColor = [UIColor colorWithHexString:@"#2C2C2C"];
    self.titleName.font = KSystemFont(__I6Width(14));
    [self addSubview:self.titleName];
    
    self.contentField = [UITextField new];
    self.contentField.font = KSHSystemFont(14);
    self.contentField.textColor = [UIColor colorWithHexString:@"#666666"];
    self.contentField.keyboardType = UIKeyboardTypeNumberPad;
    self.contentField.textAlignment = NSTextAlignmentRight;
    [self.contentField setValue:[UIColor colorWithHexString:@"#666666"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.contentField setValue:KSystemFont(__I6Width(14)) forKeyPath:@"_placeholderLabel.font"];
    [self addSubview:self.contentField];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.titleName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(__I6Width(15));
        make.centerY.equalTo(self);
        make.width.mas_offset(__I6Width(120));
    }];
    
    [self.contentField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self).offset(-__I6Width(15));
    }];
}

+ (instancetype)tableViewCellWithTableView:(UITableView *)tableView{
    
    static NSString * cellIndentfile = @"JCPlanFieldCell";
    JCPlanFieldCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndentfile];
    
    if (!cell) {
        cell = [[JCPlanFieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentfile];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)getPlanRepayment:(NSMutableDictionary *)dic andSection:(NSInteger)section andIndexRow:(NSInteger)row{
    self.titleName.text = dic[@"titleName"][section][row];
    self.contentField.placeholder = dic[@"contentName"][section][row];
}


@end

